#include "RsGisLibCalBandMath.h"
#include "ExtensionManager.h"
#include "ExtensionSession.h"
#include <QVariant>

RsGisLibCalBandMath::RsGisLibCalBandMath(RsgisPortal* ClientPortal, QWidget *parent)
{
	ui = new Ui::RsGisLibImageCalBandMath();
	ui->setupUi(this);

	Portal = ClientPortal;

	connect(ui->pushButton_OutputFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_OutputFilePath_clicked()));
	connect(ui->pushButton_BandsSelect, SIGNAL(clicked()), this, SLOT(on_action_Button_BandSelect_clicked()));
	connect(ui->pushButton_ApplyBands, SIGNAL(clicked()), this, SLOT(on_action_Button_BandApply_clicked()));

	ui->lineEdit_BandMathExpression->setText(
		"b0 + b1 + b2"
	);

	ui->lineEdit_BandNum->setText("3");

	QStringList DatatypeList;
	DatatypeList.append("undefined");
	DatatypeList.append("8 Int");
	DatatypeList.append("16 Int");
	DatatypeList.append("32 Int");
	DatatypeList.append("64 Int");
	DatatypeList.append("8 uInt");
	DatatypeList.append("16 uInt");
	DatatypeList.append("32 uInt");
	DatatypeList.append("64 uInt");
	DatatypeList.append("32 Float");
	DatatypeList.append("64 Float");
	ui->comboBox_Datatype->addItems(DatatypeList);

	ui->lineEdit_OutputFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\TestBandMath.tif");
	ui->lineEdit_GdalFormat->setText("GTIFF");
	ui->comboBox_Datatype->setCurrentIndex(10);

	ui->lineEdit_Priority->setText("16");
}


void RsGisLibCalBandMath::on_action_Button_OutputFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_OutputFilePath->setText(str.toUtf8());
}

void RsGisLibCalBandMath::on_action_Button_BandSelect_clicked()
{
	int iBandNum = ui->lineEdit_BandNum->text().toInt();

	ui_BandSelect = new Ui_RsGisLibCalBandMath_BandSelect();

	ui_BandSelect->BandNum = iBandNum;

	ui_BandSelect->setupUI(ui_BandSelect);

	ui_BandSelect->show();
}

void RsGisLibCalBandMath::on_action_Button_BandApply_clicked()
{
	QList<QVariant> SysParaList;
	SysParaList << QVariant(QString("RsGisLib"));
	SysParaList << QVariant(QString("imageCalculation"));
	SysParaList << QVariant(int(ui->lineEdit_Priority->text().toInt()));

	QList<QVariant> AlgParaList;
	AlgParaList << QVariant(QString("BandMaths"));
	AlgParaList << QVariant::fromValue<QList<QVariant>>(ui_BandSelect->BandSelectVarList);
	AlgParaList << QVariant(int(ui->lineEdit_BandNum->text().toInt()));
	AlgParaList << QVariant(QString(ui->lineEdit_OutputFilePath->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_BandMathExpression->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_GdalFormat->text()));
	AlgParaList << QVariant(int(ui->comboBox_Datatype->currentIndex()));

	QVariantList ArgList;
	ArgList << (QVariant)SysParaList;
	ArgList << (QVariant)AlgParaList;

	Portal->goAhead(ArgList);
}
